using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AirCannonWeapon : MonoBehaviour
{
    GameObject airCannonModel;
    CannonLevel cannonLevel;
    GameObject airCannonObeject;

    public float energyCost;

    public GameObject[] cannonLevelIcon;
    private void Awake()
    {
        airCannonModel = Resources.Load<GameObject>("prefabs/aircannon");
    }
    // Start is called before the first frame update
    void Start()
    {
        cannonLevel = CannonLevel.Weak;
        energyCost = -10;
    }

    // Update is called once per frame
    void Update()
    {

    }
    public void Fire()
    {
        airCannonObeject = Instantiate(airCannonModel, transform.position, Quaternion.identity);
        AirCannon airCannon = airCannonObeject.GetComponent<AirCannon>();
        airCannon.SetCannonLevel(cannonLevel);
        airCannonObeject.transform.forward = transform.forward;
    }

    public void SetCannonLevel(CannonLevel level)
    {
        cannonLevel = level;
    }

    public void DestroyCannon()
    {
        if (airCannonObeject != null)
            Destroy(airCannonObeject);
    }

    public void SwitchCannonLevel()
    {
        ++cannonLevel;
        if (cannonLevel > CannonLevel.Strong)
        {
            cannonLevel = CannonLevel.Weak;
        }
        switch (cannonLevel)
        {
            case CannonLevel.Weak:
                cannonLevelIcon[1].SetActive(false);
                cannonLevelIcon[2].SetActive(false);
                energyCost = -10;
                break;
            case CannonLevel.Normal:
                cannonLevelIcon[1].SetActive(true);
                cannonLevelIcon[2].SetActive(false);
                energyCost = -20;
                break;
            case CannonLevel.Strong:
                cannonLevelIcon[1].SetActive(true);
                cannonLevelIcon[2].SetActive(true);
                energyCost = -30;
                break;
        }
    }
}
